package com.example.demo.controller;

import com.example.informationmanagement.entity.Information;
import com.example.informationmanagement.service.InformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Optional;

@RestController
public class InformationController {
    @Autowired
    InformationService informationService;

    @GetMapping("/informations")
    public List<Information> getAllInformation() {
        return informationService.list();
    }

    @GetMapping("/information/{id}")
    public Information getInformationById(@PathVariable Long id) {
        return informationService.getById(id);
    }

    @PostMapping("/information")
    public void saveInformation(@RequestBody Information information) {
        return informationService.save(information);
    }

    @PutMapping("/information")
    public void updateInformation(@RequestBody Information information) {
        return informationService.updateById(information);
    }

    @DeleteMapping("/information")
    public void deleteInformation(Long id) {
        informationService.removeById(id);

    }
}